import moment from "moment";
import {
  BeforeInsert,
  BeforeUpdate,
  Column,
  Entity,
  PrimaryColumn,
  PrimaryGeneratedColumn,
} from "typeorm";

@Entity({ name: "essay" })
export class EssayEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ type: "varchar", length: 60 })
  essaytitle: string;

  @Column({ type: "text" })
  content: string;

  @Column({ type: "tinyint", default: 0 })
  watermarking: number;

  @Column({ type: "tinyint", default: 0 })
  del: number;

  @Column({ type: "int", default: 0 })
  view_count: number;

  @Column({ type: "int", default: 0 })
  status: number;

  @Column({ type: "varchar", nullable: true })
  created_at: string;

  @Column({ type: "varchar", nullable: true })
  updated_at: string;

  @BeforeInsert()
  createDates() {
    this.created_at = moment().format("YYYY-MM-DD HH:mm:ss");
  }

  @BeforeUpdate()
  updateDates() {
    this.updated_at = moment().format("YYYY-MM-DD HH:mm:ss");
  }
}
